import tkinter as tk
from PIL import Image,ImageTk
import webbrowser
import manage
import functions.sql as sql
import functions.exec as exec
from random import randint as r
#调整背景图大小
def get_image(filename,width,height):
    im = Image.open(filename).resize((width,height))
    return ImageTk.PhotoImage(im)
#打开帮助页
def help():
    webbrowser.open('https://blog.eastaug.top/archives/77.html',new=0,autoraise=True)
#打开赞助页
def zz():
    webbrowser.open('',new=0,autoraise=True)
#跳转到创建任务

#跳转到查询任务

#跳转到编辑任务

#跳转到删除任务

#跳转到手动删除
window= tk.Tk()
window.title('随机抽学号')
window.geometry('1024x728')

canvas_root = tk.Canvas(window,width=1024,height=728)
img = r(1,16)
im_root = get_image('photo/bg'+str(img)+'.jpg',1024,728)
canvas_root.create_image(512,364,image = im_root)

label = tk.Label(window,text='欢迎使用Data-BackUp-CTRL_1.1',bg='white',font=('宋体',50),width=30,height=2,justify='center')
label2 = tk.Label(window,text=manage.check())

menu=tk.Menu(window)

wenjian=tk.Menu(menu,tearoff=0)
wenjian.add_command(label='保存到',font=("宋体",8,"normal"))
menu.add_cascade(label="文件",menu=wenjian,font=("宋体",12,"normal"))

bangzhu = tk.Menu(menu,tearoff=0)
bangzhu.add_command(label='使用说明',command=help,font=('黑体',8,'normal'))
menu.add_cascade(label='帮助',menu=bangzhu,font=('宋体',12,'normal'))

caozuo = tk.Menu(menu,tearoff=0)
caozuo.add_command(label='创建任务',command=sql.creative,font=('宋体',8,'normal'))
caozuo.add_command(label='查询任务',command=sql.select,font=('宋体',8,'normal'))
caozuo.add_command(label='编辑任务',command=sql.change,font=('宋体',8,'normal'))
caozuo.add_command(label='删除任务',command=sql.drop,font=('宋体',8,'normal'))
caozuo.add_command(label='手动备份',command=exec.crezip,font=('宋体',8,'normal'))
menu.add_cascade(label='操作',menu=caozuo,font=('宋体',12,'normal'))

zanzhu = tk.Menu(menu,tearoff=0)
zanzhu.add_command(label='赞助',command=zz,font=('宋体',8,'normal'))
menu.add_cascade(label='赞助',menu=zanzhu,font=('宋体',12,'normal'))
window.config(menu=menu)


'''
Button1 = tk.Button(window,text='创建任务',width=30,height=3)
Button2 = tk.Button(window,text='查询任务',width=30,height=3)
Button3 = tk.Button(window,text='编辑任务',width=30,height=3)
Button4 = tk.Button(window,text='删除任务',width=30,height=3)
Button5 = tk.Button(window,text='手动备份',width=30,height=3)
Button6 = tk.Button(window,text='赞助',width=30,height=3)

Button1.place(x=150,y=250)
Button2.place(x=400,y=250)
Button3.place(x=650,y=250)
Button4.place(x=150,y=450)
Button5.place(x=400,y=450)
Button6.place(x=650,y=450)

'''
label.place(y=0)
label2.pack()
canvas_root.pack()

window.mainloop()              